package com.whstudio.chat;

import java.util.Iterator;
import java.util.Vector;

import com.whstudio.common.pattern.Subject;
import com.whstudio.common.pattern.Subscriber;
import com.whstudio.util.xml.CDocument;

/**
 * 聊天室
 * 负责处理用户的进入、退出和转发消息的功能
 * @author wbwanggp
 *
 */
public abstract class AbstractChatRoom extends Subject {
	@Override
	public abstract CDocument getUsersByXml();
	
	public Integer getGuestCount(){
		Vector<Subscriber> subscribers=getSubscribers();
		Integer guestCount=Integer.valueOf(0);
		for (Iterator<Subscriber> iterator = subscribers.iterator(); iterator.hasNext();) {
			Subscriber subscriber =  iterator.next();
			if(subscriber.getId()==0){
				guestCount=guestCount+1;
			}
		}
		return guestCount;
	}

	@Override
	public void notifyObserver(Subscriber s, Object o) {
		s.update(this, o);
	}

}
